<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="软中断、发起内核调用；用户态，内核态， 系统调用： 用户模式（空间）、内核模式（空间）； 用户模式无法完成的操作，需要系统调用；实现模式切换； 内核的功用：进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能； 时间片：按时间片划分资源， 进程优先级概念： 内核负责进程调度，根据优先级调度资源； 进程的当前状态保存下来； 内核在进程切换时需要保存上一个进程运行的现场。保存现场；–&gt; 恢">
<meta property="og:type" content="article">
<meta property="og:title" content="14.linux进程原理、类型和内核状态">
<meta property="og:url" content="http://yoursite.com/2020/06/15/14-linux%E8%BF%9B%E7%A8%8B%E5%8E%9F%E7%90%86%E3%80%81%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%86%85%E6%A0%B8%E7%8A%B6%E6%80%81/index.html">
<meta property="og:site_name" content="Lcxiao&#39;s blog">
<meta property="og:description" content="软中断、发起内核调用；用户态，内核态， 系统调用： 用户模式（空间）、内核模式（空间）； 用户模式无法完成的操作，需要系统调用；实现模式切换； 内核的功用：进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能； 时间片：按时间片划分资源， 进程优先级概念： 内核负责进程调度，根据优先级调度资源； 进程的当前状态保存下来； 内核在进程切换时需要保存上一个进程运行的现场。保存现场；–&gt; 恢">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-06-15T05:08:34.000Z">
<meta property="article:modified_time" content="2020-06-15T13:08:48.763Z">
<meta property="article:author" content="lcxiao">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/06/15/14-linux%E8%BF%9B%E7%A8%8B%E5%8E%9F%E7%90%86%E3%80%81%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%86%85%E6%A0%B8%E7%8A%B6%E6%80%81/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>14.linux进程原理、类型和内核状态 | Lcxiao's blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="Lcxiao's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Lcxiao's blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-lifestyle">

    <a href="/lifestyle/" rel="section"><i class="fa fa-fw fa-lifestyle"></i>LifeStyle</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/15/14-linux%E8%BF%9B%E7%A8%8B%E5%8E%9F%E7%90%86%E3%80%81%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%86%85%E6%A0%B8%E7%8A%B6%E6%80%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="lcxiao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lcxiao's blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          14.linux进程原理、类型和内核状态
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-06-15 13:08:34 / 修改时间：21:08:48" itemprop="dateCreated datePublished" datetime="2020-06-15T13:08:34+08:00">2020-06-15</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>软中断、发起内核调用；用户态，内核态，</p>
<p>系统调用：</p>
<p>用户模式（空间）、内核模式（空间）；</p>
<p>用户模式无法完成的操作，需要系统调用；实现模式切换；</p>
<p>内核的功用：进程管理、文件系统、网络功能、内存管理、驱动程序、安全功能；</p>
<p>时间片：按时间片划分资源，</p>
<p>进程优先级概念：</p>
<p>内核负责进程调度，根据优先级调度资源；</p>
<p>进程的当前状态保存下来；</p>
<p>内核在进程切换时需要保存上一个进程运行的现场。保存现场；–&gt; 恢复现场、切换太多会浪费时间；</p>
<p>进程–&gt; 运行中的程序的一个副本：</p>
<p>存在生命周期：</p>
<p>每一个进程结构都相同</p>
<p>内核存储进程的格式：task struct</p>
<p>多个人的task struct组成的链表：链表：有先后次序、（循环链表、双向链表、双向循环链表）</p>
<p>任何进程、在内核无漏洞的情况下、无权运行特权指令；</p>
<p>如果要运行，会出发中断，会立即唤醒内核，内核处理中断；</p>
<p>进程创建：</p>
<p>启动启动时–&gt;运行内核–&gt;创建第一个进程（init）（初始化进程）表示内核空间和用户空间都已经创建，init是负责用户空间管理–&gt;创建子进程</p>
<p>除了init（内核创建）之外，其余进程都是由父进程创建，fork（），clone（）父进程的内存空间也是子进程的内存空间，子进程创建数据需要写实复制。进程 必须是父进程给他销毁（白发送黑发）；子进程是为父进程完成特定任务，子进程任务时，父进程在等待状态，子进程任务结束后，父进程销毁，并继续往下走；</p>
<p>优先级：</p>
<p>0-139</p>
<p>1-99：实时优先级：数字越大—&gt;优先级越高</p>
<p>100-139：静态优先级；用户可控的；，数字越小&lt;—-优先级越高；</p>
<p>NICE值：-20 —- 19</p>
<p>​                    |        |</p>
<p>​                100        139</p>
<p>可以调整一个进程的nice值来控制优先级；</p>
<p>Big O</p>
<p>O(1)、O(logn)、O(n),O(2^n)、O(n^2)</p>
<p>|</p>
<p>|——————————————O(1)</p>
<p>|</p>
<p>|——————————————</p>
<p>优先队列：</p>
<p>运行队列，过期队列；</p>
<p>进程结构：task struct</p>
<p>状态</p>
<p>flags</p>
<p>父进程</p>
<p>。。。</p>
<p>内核对内存的分配；</p>
<p>分割成内存片，一般为4k，页框，用存储页面数据；</p>
<p>每一个进程都以为自己是唯一的进程；</p>
<p>线性地址空间；</p>
<p>内核只给进程它所需要的；</p>
<p>虚拟内存空间；</p>
<p>堆栈</p>
<p>堆向栈增长，栈向堆生长；</p>
<p>LRU算法，最近最少使用，分配到交换分区；</p>
<p>MMU:Memory Management Unit:内存管理单元；</p>
<p>转换虚拟内存空间和物理内存的映射关系；</p>
<p>缺页；</p>
<p>常驻内存级；必须在内存</p>
<p>虚拟内存级：可被交换的内存空间；</p>
<p>IPC：Inter Press Communication 进程间通信；</p>
<p>同一主机上：</p>
<p>​    singal</p>
<p>​    shm：shared memory</p>
<p>​    semerphor：</p>
<p>跨主机：</p>
<p>RPC：remote procecure call：远程过程调用；</p>
<p>socket文件：记录自己和对方的端口；</p>
<p>​        A                                B</p>
<p>|———|                      |———|</p>
<p>|socket|—————   |socket|</p>
<p>|———|                      |———|</p>
<p>​    |                                        |</p>
<p>​    |                                        |</p>
<p>内核                                    内核</p>
<p>Linux内核：抢占式多任务；</p>
<p>进程类型：</p>
<p>​    守护进程：daemon，在系统引导过程中启动的进程，跟终端无关的进程</p>
<p>​    前台进程：根终端有关，通过终端启动的进程；</p>
<p>​        注意，也可把在前台启动的进程送往后台，以守护模式运行；</p>
<p>进程状态：</p>
<p>​    运行态：running</p>
<p>​    就绪态：ready</p>
<p>​    睡眠态：</p>
<p>​        可中断:interruptable；</p>
<p>​        不可中端：uninterruptable；</p>
<p>​    停止态：暂停于内存中，但不会被调度，除非手动启动：stopped</p>
<p>​    僵尸态：zombie ，（子进程运行中，父进程突然就挂了）</p>
<p>进程的分类：</p>
<p>CPU-BOUND：cpu密集型进程（多分cpu）</p>
<p>IO-BOUND：IO密集型进程（提高优先级）</p>
<p>IO：进程运行过程中加载数据，IO分2段，1.数据从磁盘装入内核。2内核复制一份到内存中，</p>
<p>《《linux内核设计与实现》》。《《深入理解linux内核》》</p>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/06/15/13-%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/" rel="prev" title="13.网络基础">
      <i class="fa fa-chevron-left"></i> 13.网络基础
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/06/15/15-Linux%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86%E5%91%BD%E4%BB%A4/" rel="next" title="15.Linux进程管理命令">
      15.Linux进程管理命令 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">lcxiao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://163.com/" title="http:&#x2F;&#x2F;163.com" rel="noopener" target="_blank">163</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://baidu.com/" title="http:&#x2F;&#x2F;baidu.com" rel="noopener" target="_blank">baidu</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="/dalipan.com" title="dalipan.com">dalipan</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://google.com/" title="https:&#x2F;&#x2F;google.com" rel="noopener" target="_blank">Google</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">lcxiao</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
